#全局配置和fixture夹具管理

import pytest
import logging
from datetime import datetime
from selenium import webdriver
#from common.logger import setup_logger
'''
@pytest.fixture(scope="session")
def logger():
    """全局日志配置"""
    return setup_logger()

@pytest.fixture(scope="function")
def api_client():
    """API测试客户端"""
    from common.base_api import APIClient
    client = APIClient(base_url="https://api.example.com")
    yield client
    client.close()
    
    '''

@pytest.fixture(scope="function")
def browser():
    """浏览器实例"""
    options = webdriver.ChromeOptions()
    options.add_argument("--headless")
    driver = webdriver.Chrome(options=options)
    driver.implicitly_wait(10)
    yield driver
    driver.quit()

@pytest.fixture(scope="session")
def test_data():
    """测试数据加载"""
    from utils.data_loader import load_test_data
    return load_test_data("data/test_data.json")

def pytest_runtest_makereport(item, call):
    """测试报告钩子函数"""
    if call.when == "call":
        if call.excinfo is not None:
            logging.error(f"测试失败: {item.name}, 错误: {call.excinfo}")